What is Queue Data Structure? | Data Structure Tutorial
In this article, you will learn about:
- What is Queue?
- Operations of Queue
- Applications of Queue
What is Queue?
A queue is a functional data structure in programming. It is kind of like the first person in the queue always gets a chance to get inside and come out from the place. Queue follows the First In First Out (FIFO) approach. It means that the item that goes in the line first will come out first. In the programming language, inserting an element in the queue is called enqueue, and removing an element from the queue is called dequeue. It is implemented in the same way in other programming languages.
Operations of Queue
A queue is an object that has the following operations:
- Enqueue: Insert an item at the end of the queue.
- Dequeue: Removing an item from the front of the queue.
- IsEmpty: It helps in verifying before removing the element from the queue if is it empty.
- IsFull: It helps in verifying before inserting an element in the queue if is it full.
- Peek: Fetch the value of the front of the queue without removing the element from the queue.
Working of Queue:
Queue works as follows:
- Two-pointers FRONT and REAR.
- FRONT traces the first item of the queue.
- REAR traces the last item of the queue.
- Set the value of the FRONT and REAR to -1.
Enqueue Operation:
- First, check if the queue is full.
- Set the value of the FRONT to 0 for the first element.
- Increase the REAR value by 1.
- Add the new item in the position increased by REAR.
Dequeue Operations:
- First, check if the queue is empty.
- Point the value pointer by FRONT.
- Increase the value of FRONT by 1.
- Reset the values of FRONT and REAR to -1 for the last element.
Application of Queue:
- CPU scheduling and Disk Scheduling
- When the data is transferred asynchronously between two processes.
- Handling of interrupts in real-time systems.
- Call center phone systems use Queues to keep people on hold in the lines.


